Fork me on GitHub
#sql
<
2023-08-23
>
kpav19:08:34

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 ...

seancorfield19:08:25

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?

seancorfield19:08:42

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

seancorfield19:08:43

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).

😂 2
seancorfield19:08:43

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

kpav20:08:17

ah great thanks!

kpav20:08:33

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

seancorfield20:08:37

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).

seancorfield20:08:28

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

seancorfield20:08:50

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

kpav20:08:23

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

kpav20:08:57

Seems to do the trick, thanks!

2