sql

kpav 2023-08-23T19:17:34.191629Z

I am probably missing something in the docs, but is there a way in HoneSQL to use a CREATE OR REPLACE VIEW ... statement? Postgres does not like {:create-view [:view_name :if-not-exists] ...} / CREATE VIEW view_name IF NOT EXISTS ...

seancorfield 2023-08-23T19:22:25.462349Z

PG doesn't support that? Wow. Create a GH issue and I'll add something for that. Does PG support IF NOT EXISTS for other CREATE clauses?

seancorfield 2023-08-23T19:27:42.616819Z

Looks like recent PG versions have added support for this (9.5 onward maybe?).

seancorfield 2023-08-23T19:32:43.264009Z

Hmm, looks very inconsistent. Some CREATE statements got added with IF NOT EXISTS, some got OR REPLACE, going back a few versions some have neither. What a mess (my opinion of PG in general).

😂 1
seancorfield 2023-08-23T19:42:43.145499Z

No worries about creating an issue. Looks like only :create-view needs this variant so I'm adding it now.

kpav 2023-08-23T20:00:17.955259Z

ah great thanks!

kpav 2023-08-23T20:03:33.965869Z

I can confirm {:create-table [:name :if-not-exists] ... } does work as expected at least

seancorfield 2023-08-23T20:36:37.085449Z

Yeah, it seems like PG eventually added IF NOT EXISTS support to almost everything except CREATE VIEW (and CREATE FUNCTION but HoneySQL can't really support that since it would inline arbitrary SQL).

seancorfield 2023-08-23T20:40:28.398959Z

There's a new 2.4.9999-SNAPSHOT version if you want to try that, which includes :create-or-replace-view for this.

seancorfield 2023-08-23T20:40:50.575879Z

Otherwise a full release will appear next week with a bunch of new stuff in it.

kpav 2023-08-23T20:41:23.116279Z

Wow well that was quick! I'll throw that in my deps to test it out

kpav 2023-08-23T20:48:57.903539Z

Seems to do the trick, thanks!

👍🏻 1